//
//  LeftMenuView.m
//  ArtCircle
//
//  Created by sunbin on 2017/5/20.
//  Copyright © 2017年 HuaYue. All rights reserved.
//

#import "LeftMenuView.h"
#import "LeftHeader.h"

@interface LeftMenuView()<UITableViewDelegate ,UITableViewDataSource>

@property (nonatomic ,strong) UITableView    *contentTableView;
@property (nonatomic, strong) NSMutableArray *cellDefs;


@end

@implementation LeftMenuView
{
    ACUserModel *model ;
}
static NSString *const identifier = @"identifier";


-(instancetype)initWithFrame:(CGRect)frame{
    
    if(self = [super initWithFrame:frame]){
        [self initView];
    }
    return  self;
}


-(void)initView{
    
    [self cellData];
    
    
    self.backgroundColor = [UIColor blackColor];
    
    _contentTableView = [[UITableView alloc] initWithFrame:self.frame style:UITableViewStyleGrouped];
    
    _contentTableView.dataSource    = self;
    _contentTableView.delegate      = self;
    _contentTableView.scrollEnabled = NO;
    
    
    _contentTableView.backgroundColor = [UIColor blackColor];
    _contentTableView.separatorStyle  = UITableViewCellSeparatorStyleSingleLine;
    _contentTableView.separatorColor =  [UIColor whiteColor];

    
    [_contentTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:identifier];
    
    [_contentTableView  registerNib:[UINib nibWithNibName:@"LeftHeader" bundle:nil] forHeaderFooterViewReuseIdentifier:@"LeftHeaderID"];
    
    
    
    
    [self addSubview:_contentTableView];

}





- (void)cellData
{
    _cellDefs = [[NSMutableArray alloc] initWithArray:@[@"钱包",@"个人资料",@"账号相关"]];
    
    model = [[YConfig sharedYConfig] searchData];
    
    
}
#pragma make -UITableViewDataSource

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _cellDefs.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
        
    }

    
    cell.accessoryType       = UITableViewCellAccessoryDisclosureIndicator;
    
    
    cell.textLabel.text = [_cellDefs objectAtIndex:indexPath.row];
    
    return cell;
}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    LeftHeader *headView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"LeftHeaderID"];
   
    [headView loadData:model];

    return headView;
    
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50.f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 238.f;
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    
    cell.backgroundColor = [UIColor clearColor];
    cell.textLabel.textColor = [UIColor colorWithRed:62/255.0f green:68/255.0f blue:75/255.0f alpha:1.0f];
    cell.textLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:17];

    
    if ([cell respondsToSelector:@selector(setSeparatorInset:)])
    {   [cell setSeparatorInset:UIEdgeInsetsMake(0, 15, 0, 15)];}
    if ([cell respondsToSelector:@selector(setLayoutMargins:)])
    {   [cell setLayoutMargins:UIEdgeInsetsMake(0, 15, 0, 15)];}
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if ([self.delegate respondsToSelector:@selector(leftMenuViewClick:)]) {
        [self.delegate leftMenuViewClick:indexPath.row];
    }
}


@end
